<!--用车首页-->
<template>
  <div id="Home">
    <div class="header">
      <div class="header-top">
        <div class="header-search">
          <p class="header-text">{{this.$store.state.user.loginName}}管理员欢迎回来!</p>
          <van-icon @click="toSearch" :name="require('./images/search@2x.png')" size="0.5rem" />
        </div>
        <p class="header-text weather-text">杭州天气 19°</p>
      </div>
      <div class="data-list">
        <div>
          <p>{{topData.indexCout1}}</p>
          <p>{{topData.indexCout1Value}}</p>
        </div>
        <span class="line"></span>
        <div>
          <p>{{topData.indexCout2}}</p>
          <p>{{topData.indexCout2Value}}</p>
        </div>
        <span class="line"></span>
        <div>
          <p>{{topData.indexCout3}}</p>
          <p>{{topData.indexCout3Value}}</p>
        </div>
        <span class="line"></span>
        <div>
          <p>{{topData.indexCout4}}</p>
          <p>{{topData.indexCout4Value}}</p>
        </div>
      </div>
    </div>
    <div class="content-conatiner">
      <Menu-list :data="meunList" />
      <div class="marginTop30">
           <Notice-list />
      </div>
    </div>
  </div>
</template>
<script>
import MenuList from "../../components/MenuLlist";
import NoticeList from "../../components/NoticeList";
//   {
//                 id: 3,
//                 icon: require("./images/my_order@2x.png"),
//                 text: "驾驶员任务",
//                 router: "/driverTaskList"
//                 },
//                 {
//                 id: 4,
//                 icon: require("./images/my_evaluate@2x.png"),
//                 text: "我的调度",
//                 router: "/dispatchList"
//                 }
export default {
  name: "Home",
  data() {
    return {
      loginName: "",
      meunList: [],
      //后端返回字段判断
      topData:{
        indexCout1: 0,
        indexCout1Value: "出车趟次",
        indexCout2: 0,
        indexCout2Value: "出车天数",
        indexCout3: 0,
        indexCout3Value: "接单数",
        indexCout4: 0,
        indexCout4Value: "计费里程"
      }
    };
  },
  mounted() {
     let user=localStorage.getItem('user') 
     if(user&&user!=""){
       this.$store.commit({
            type: "setUser",
            data: JSON.parse(user)
       });  
       this.getType();
    
     }
    
  },
  methods: {
    //用户判断
    getType() {
        console.log(this.$store.state.user)
        let isType=this.$store.state.user.isType;
        let userType=this.$store.state.user.userType;
        //用户判断
      if (isType == 0) {
        if (userType == 3) {
           this.getListData(0)
          //用车单位管理员
           this.meunList=[
                {
                id: 0,
                icon: require("./images/local_apply@2x.png"),
                text: "本地申请",
                router: "/apply"
                },
                {
                id: 1,
                icon: require("./images/other_apply@2x.png"),
                text: "异地申请",
                router: "/applyOther"
                },
                {
                id: 2,
                icon: require("./images/my_order@2x.png"),
                text: "我的订单",
                router: "/otherApply"
                },
                {
                id: 3,
                icon: require("./images/my_evaluate@2x.png"),
                text: "我的评价",
                router: "/otherApply"
                },
            ]
        } else {
           this.getListData(1)

          //服务单位管理员
          this.meunList=[
                {
                id: 0,
                icon: require("./images/icon_dispatch@2x.png"),
                text: "调度处理",
                router: "/dispatchList"
                },
                {
                id: 1,
                icon: require("./images/icon_order@2x.png"),
                text: "预约登记",
                router: "/otherApply"
                },
                {
                id: 2,
                icon: require("./images/icon_other_apply@2x.png"),
                text: "异地申请",
                router: "/otherApply"
                },
                {
                id: 3,
                icon: require("./images/icon_control@2x.png"),
                text: "车辆监控",
                router: "/otherApply"
                },
            ]
        }
      } else if (isType == 1) {
          this.getListData(2)
        //驾驶员
        this.meunList=[
                {
                id: 0,
                icon: require("./images/icon_list@2x.png"),
                text: "任务列表",
                router: "/driverList"
                },
                {
                id: 1,
                icon: require("./images/icon_order_take@2x.png"),
                text: "接单出车回车",
                router: "/otherApply"
                },
                {
                id: 2,
                icon: require("./images/icon_clock_in@2x.png"),
                text: "上班打卡",
                router: "/otherApply"
                },
                {
                id: 3,
                icon: require("./images/icon_malfunction_post@2x.png"),
                text: "事故上报",
                router: "/otherApply"
                },
                {
                id: 4,
                icon: require("./images/icon_car_post@2x.png"),
                text: "车况上报",
                router: "/otherApply"
                },
            ]
      }
    },
    toSearch() {
      this.$router.push({ path: "/search" });
    },
    //获取顶部数据
    getListData(type){
        let url=""
       switch(type){
           case 0:
             url="";
             break;
           case 1:
             url="/index/fuwuIndex";
             break;
           case 2:
             url="/index/driverIndex";
             break;
       }
       this.$http
        .get(url, {
            userId:this.$store.state.user.id
       })
        .then(result => {
          console.log(result);
          this.topData=result.data
        })
    }
  },
  components: {
    "Menu-list": MenuList,
    "Notice-list": NoticeList
  }
};
</script>
<style scoped>
.header {
  height: 455px;
  background: url("./images/home_bg@2x.png") no-repeat center;
  background-size: 100% 100%;
  background-color: aquamarine;
  padding: 0 20px;
}
.header-top {
  padding: 34px 0;
}
.header-search {
  margin-bottom: 10px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
.header-text {
  font-size: 30px;
  font-family: "PingFang SC";
  font-weight: bold;
  color: rgba(255, 255, 255, 1);
}
.content-conatiner {
  margin: 0 20px;
  position: relative;
  top: -85.5px;
}
.marginTop30 {
  margin-top: 30px;
}
.data-list {
  margin-top: 60px;
  display: flex;
  flex-direction: row;
  align-items: center;
  width: 710px;
  height: 128px;
  background: rgba(205, 205, 205, 0.5);
  border-radius: 12px;
  font-size: 30px;
  color: #ffffff;
  font-weight: 400;
}
.data-list > div {
  padding: 20px 0;
  flex: 1;
  text-align: center;
}
.data-list > div p:nth-of-type(2) {
  margin-top: 20px;
}
.line {
  display: block;
  height: 40px;
  width: 1px;
  background: #ffffff;
}
</style>